package com.kharthick.game;

import java.awt.Graphics2D;
import java.awt.Shape;

public class Marker {
	
	public final int POSITIONS;
	public final int INCREMENT;
	public final boolean VERTICAL;
	public final int START_X, START_Y;
	
	private int currentPosition;
	private int x;
	private int y;
	private int height;
	private int width;
	
	private Shape shape;
	private String shapeName;
	private Graphics2D buffer;

	
	public Marker(int startX, int startY, int positions, int increment, boolean vertical, Graphics2D buf){
		x = START_X = startX;
		y = START_Y = startY;
		POSITIONS = positions;
		INCREMENT = increment;
		VERTICAL = vertical;
		buffer = buf;
		
		//default shape
		shapeName = "oval";
		height = 10;
		width = 10;
		currentPosition = 1;
		
	}
	
	public void setCurrentPosition(int pos){
		if(pos > 0 && pos <= POSITIONS)
			currentPosition = pos;
	}
	
	public int geCurrentPosition(){
		return currentPosition;
	}
	
	public void setShapeRectangle(int h, int w){
		shapeName = "rectangle";
		height = h;
		width = w;
	}
	public void setShapeOval(int h, int w){
		shapeName = "oval";
		height = h;
		width = w;
	}
	public void setShape(Shape s){
		shape = s;
		shapeName = null;
	}
	
	public void move(int pressedKey){
		if(VERTICAL){
			if(pressedKey == 38){ 
				increasePosition();
			}
			else if(pressedKey == 40){
				decreasePosition();
			}
			y = START_Y + (INCREMENT *  (currentPosition - 1));
		}
		else {
			if(pressedKey == 37){ 
				increasePosition();
			}
			else if(pressedKey == 39){
				decreasePosition();
			}
			x = START_X + (INCREMENT *  (currentPosition - 1));	
		}
	}
	
	private void decreasePosition() {
		if(currentPosition == POSITIONS)
			currentPosition = 1;
		else
			currentPosition++;
	}

	private void increasePosition() {
		if(currentPosition == 1)
			currentPosition = POSITIONS;
		else
			currentPosition--;	
	}

	public void draw(){
		if(shapeName == null){
			buffer.fill(shape);
		}
		else if(shapeName == "rectangle"){
			buffer.fillRect(x, y, height, width);
		}
		else if(shapeName == "oval"){
			buffer.fillOval(x, y, height, width);
		}
	}
	
}
